import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';


export default {
	bootstrap () {
		const mock = new MockAdapter(axios);

		mock.onPost('/api-user.html').reply(confing => {
			return new Promise((resolve, reject) => {
				setTimeout(() => {
					let list = [];
					for (let i = 1, l = 100; i <= l; i++) {
						list.push({
							user_id: i,
							name: 'qian ' + i,
							head: 'https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=600979763,997039067&fm=58&bpow=600&bpoh=900',
						});
					}
					resolve([200, {
						code: 0,
						data: {
							list: list,
							total: 1000,
							sign: 200,
						}
					}]);
				}, 0);
			});
		});

		mock.onPost('/api-lottery.html').reply(confing => {
			return new Promise((resolve, reject) => {
				setTimeout(() => {
					let list = [];
					for (let i = 1, l = 20; i <= l; i++) {
						list.push({
							user_id: i,
							name: 'qian ' + Math.floor(l * Math.random()),
							head: 'https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=600979763,997039067&fm=58&bpow=600&bpoh=900',
						});
					}
					resolve([200, {
						code: 0,
						data: {
							list: list,
						}
					}]);
				}, 0);
			});
		});

		mock.onPost('/api-winner.html').reply(confing => {
			return new Promise((resolve, reject) => {
				setTimeout(() => {
					function generateList() {
						let list = [];
						for (let i = 1, l = 20; i <= l; i++) {
							let id = Math.floor(l * Math.random());
							list.push({
								user_id: i,
								name: 'qian ' + id,
								head: 'https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=600979763,997039067&fm=58&bpow=600&bpoh=900',
								sex: Math.floor(2 * Math.random()) + 1,
								tel: id,
								company: id,
								state: Math.floor(2 * Math.random()),
							});
						}
						return list;
					}

					resolve([200, {
						code: 0,
						data: {
							list: [
								{
									name: '特等奖',
									list: generateList(),
								},
								{
									name: '一等奖',
									list: generateList(),
								},
								{
									name: '二等奖',
									list: generateList(),
								},
								{
									name: '三等奖',
									list: generateList(),
								},
							],
						}
					}]);
				}, 0);
			});
		});

		mock.onPost('/api-prize.html').reply(confing => {
			return new Promise((resolve, reject) => {
				setTimeout(() => {
					resolve([200, {
						code: 0,
						data: {
							list: [
								{name: '特等奖', value: 1, num: 1},
								{name: '一等奖', value: 2, num: 2},
								{name: '二等奖', value: 3, num: 3},
								{name: '三等奖', value: 4, num: 40},
							],
						}
					}]);
				}, 0);
			});
		});

		mock.onPost('/api-clear.html').reply(confing => {
			return new Promise((resolve, reject) => {
				setTimeout(() => {
					resolve([200, {
						code: 0,
					}]);
				}, 0);
			});
		});

		mock.onPost('/api-accept.html').reply(confing => {
			return new Promise((resolve, reject) => {
				setTimeout(() => {
					resolve([200, {
						code: 0,
					}]);
				}, 0);
			});
		});

		mock.onPost('/api-delete.html').reply(confing => {
			return new Promise((resolve, reject) => {
				setTimeout(() => {
					resolve([200, {
						code: 0,
					}]);
				}, 0);
			});
		});

		mock.onPost('/api-truncate.html').reply(confing => {
			return new Promise((resolve, reject) => {
				setTimeout(() => {
					resolve([200, {
						code: 0,
					}]);
				}, 0);
			});
		});
	}
};